# -*- coding: utf-8 -*-
# File:contact_page.py
# Time: 
# Author : xingtiantian
import allure
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

from qiyeweixin.base.basepage import BasePage
from qiyeweixin.pages.add_member_page import AddMemberPage
from qiyeweixin.utils.log import logger


class ContactPage(BasePage):
    """通讯录界面"""
    _ADD_MEMBER_BTN = (By.XPATH, '//div[@class="ww_operationBar"]//a[contains(@class,"js_add_member")]')
    _MEMBER_LIST = (By.XPATH, '//tbody[@id="member_list"]//tr/td[2]')
    _MEMBER_CHECKBOX = (By.XPATH, "//tbody[@id='member_list']/tr[1]/td[1]/input[contains(@class, 'ww_checkbox')]")

    @allure.step("进入添加成员页面")
    def goto_add_member(self):
        self.wait_locate(*self._MEMBER_CHECKBOX)  # 等待通讯录列表 复选框 出现
        self.find_ele_click(*self._ADD_MEMBER_BTN)  # 点击 添加成员 按钮
        logger.info("进入添加成员页面")
        return AddMemberPage(self.driver)

    @allure.step("获取通讯录成员姓名列表")
    def get_member_name_list(self):
        self.wait_locate(*self._MEMBER_CHECKBOX)  # 等待通讯录列表 复选框 出现
        member_list = self.find_eles(*self._MEMBER_LIST)  # 获取通讯录列表
        name_list = []
        for member in member_list:
            name_list.append(member.text)
        logger.info(f'成功获取成员信息，成员信息为{name_list}')
        return name_list
